package Math;

public class _231_PowerofTwo {
    public boolean isPowerOfTwo(int n) {
        if (n == 0) {
            return false;
        }else if(n==1){
            return true;
        }else{
            int temp = n;
            while (temp != 1) {
                if (temp % 2 != 0) {
                    return false;
                }
                temp/=2;
            }
        }
        return true;
    }

    //reference quicker solution
    public boolean isPowerOfTwo1(int n) {
        if (n <= 0)
            return false;
        int ones = 0;
        for (int i = 1; i <= 32; ++i) {
            ones += n & 1;
            n = n >> 1;
        }
        return ones == 1;
    }
}
